package com.example.petcare.mapper;


import com.example.petcare.pojo.HostDemand;
import com.example.petcare.pojo.Provider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ProviderMapper {

    // 根据用户名查询用户
    @Select("select * from provider where username = #{username}")
    Provider findByUsername(String username);

    // 注册
    @Insert("insert into provider(username, password, create_time, update_time)" +
            "values(#{username}, #{password}, now(), now())")
    public void add(String username, String password);

    // 更新
    @Update("update provider set provider_name=#{providerName}, provider_email=#{providerEmail}," +
            "provider_phone=#{providerPhone}, provider_address=#{providerAddress},update_time=#{updateTime}," +
            "provider_status=#{providerStatus},reject_status=#{rejectStatus},provider_pic=#{providerPic} " +
            "where provider_id=#{providerId}")
    void update(Provider provider);

    // 更新密码
    @Update("update provider set password=#{md5String},update_time=now() where provider_id=#{providerId}")
    void updatePwd(String md5String, Integer providerId);

    // 检查是否有未完成的订单
    @Select("select count(*) from host_demand where provider_id=#{providerId} and order_status=0")
    Integer checkOrder(Integer providerId);


}
